/**
 *
 * @author 
 * 深度管理、排序类
 */
class ArraySort {
	public constructor() {
	}
    private static _listArr: Array<any>;

    public static setDepth(Obj:egret.DisplayObjectContainer,thisObj:any) {
        //MC深度排序
        this._listArr = [];
        //console.log("THIS_: ",thisObj.numChildren);
        for(var i = 0;i < thisObj.numChildren;i++) {
           this._listArr.push({ "star": thisObj.getChildAt(i).y,"etype": thisObj.getChildAt(i),"ejob": i,"eid": i });          
        }
        this._listArr.sort(this.sortMoreFun(["star","etype"],[0,0]));     
        
        for(var j = 0;j < this._listArr.length;j++) {
           // console.log(this._listArr[j]);
            thisObj.setChildIndex(this._listArr[j].etype,j);
        }
    }
    
    /* this._listArr.push({ "star": 1,"etype": 5,"ejob": 1,"eid": 4 }); 
         this._listArr.push({ "star": 2,"etype": 6,"ejob": 2,"eid": 3 });
         this._listArr.push({ "star": 3,"etype": 7,"ejob": 3,"eid": 2 });
         this._listArr.push({ "star": 4,"etype": 8,"ejob": 4,"eid": 1 });
         this._listArr.sort(this.sortMoreFun(["star","etype","ejob","eid"],[0,1,0,0]));     
       */
    //sortarr相应参数 为0是是从小到大，为1时是从大到小 默认从大到小 
    public static sortMoreFun = function(strarr: any[],sortarr: any[] = null) {
        return function(obj1,obj2) {
            var valarr: number[] = [];
            var sorlen: number = 0;
            if(sortarr) sorlen = sortarr.length;
            var chanum: number;
            var bc;
            for(bc in strarr) {
                bc = parseInt(bc);
                chanum = parseInt(obj1[strarr[bc]]) - parseInt(obj2[strarr[bc]]);
                if(chanum == 0) {
                    continue;
                } else {
                    if(sorlen > bc && sortarr[bc] == 0) {
                        return chanum;
                    } else {
                        return -chanum;
                    }
                }
            }
            return 0;
        }
    }
}
